home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-rdflib / rdflib_tools / EARLPlugin.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  2.3 KB  |  83 lines

  1. """ A Nose Plugin for EARL.
  2.  
  3. See Also: 
  4.   http://nose.python-hosting.com/
  5.   http://www.w3.org/TR/EARL10-Schema/ 
  6.  
  7. """
  8.  
  9. import logging
  10. import sys
  11.  
  12. from nose.plugins import Plugin
  13. from nose.suite import TestModule
  14.  
  15. from rdflib import URIRef, BNode, Literal
  16. from rdflib import RDF, RDFS
  17. from rdflib.Graph import Graph
  18. from rdflib.Namespace import NamespaceDict as Namespace
  19. from rdflib.util import date_time
  20.  
  21. log = logging.getLogger(__name__)
  22.  
  23. EARL = Namespace("http://www.w3.org/ns/earl#")
  24.  
  25.  
  26. class EARLPlugin(Plugin):
  27.     """
  28.     Activate the EARL plugin to generate a report of the test results
  29.     using EARL.
  30.     """
  31.     name = 'EARL'
  32.     
  33.     def begin(self):
  34.         self.graph = Graph()
  35.         self.graph.bind("earl", EARL.uri)
  36.  
  37.     def finalize(self, result):
  38.         # TODO: add plugin options for specifying where to send
  39.         # output.
  40.         self.graph.serialize("file:results-%s.rdf" % date_time(), format="pretty-xml")
  41.  
  42.     def addDeprecated(self, test):
  43.         print "Deprecated: %s" % test
  44.  
  45.     def addError(self, test, err, capt):
  46.         print "Error: %s" % test
  47.  
  48.     def addFailure(self, test, err, capt, tb_info):
  49.         print "Failure: %s" % test
  50.  
  51.     def addSkip(self, test):
  52.         print "Skip: %s" % test
  53.  
  54.     def addSuccess(self, test, capt):
  55.         result = BNode() # TODO: coin URIRef
  56.         self.graph.add((result, RDFS.label, Literal(test)))
  57.         self.graph.add((result, RDFS.comment, Literal(type(test))))
  58.         self.graph.add((result, RDF.type, EARL.TestResult))
  59.         self.graph.add((result, EARL.outcome, EARL["pass"]))
  60.         # etc
  61.  
  62. """
  63. <earl:TestResult rdf:about="#result">
  64.   <earl:outcome rdf:resource="http://www.w3.org/ns/earl#fail"/>
  65.   <dc:title xml:lang="en">Invalid Markup (code #353)</dc:title>
  66.   <dc:description rdf:parseType="Literal" xml:lang="en">
  67.     <div xmlns="http://www.w3.org/1999/xhtml">
  68.       <p>The <code>table</code> element is not allowed to appear
  69.         inside a <code>p</code> element</p>
  70.     </div>
  71.   </dc:description>
  72.   <dc:date rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2006-08-13</dc:date>
  73.   <earl:pointer rdf:resource="#xpointer"/>
  74.   <earl:info rdf:parseType="Literal" xml:lang="en">
  75.     <div xmlns="http://www.w3.org/1999/xhtml">
  76.       <p>It seems the <code>p</code> element has not been closed</p>
  77.     </div>
  78.   </earl:info>
  79. </earl:TestResult>
  80. """
  81.  
  82.  
  83.